package org.xhnews;

import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.ui.UiApplication;

import org.xhnews.log.RaspberryLogger;
import org.xhnews.preferences.Preferences;
import org.xhnews.services.BackgroundService;

import rimx.streamingtest.PlayerScreen;

public class StartupBo {
	private Thread _thread;

	public StartupBo() {
		_thread = new Thread(new StartupJob());

	}

	public void start() {
		_thread.start();
	}

	public class StartupJob extends Thread {
		public void run() {
			ApplicationManager am = ApplicationManager.getApplicationManager();
			while (am.inStartup() || Preferences.running_count == 0) {
				try {
					sleep(2000);
				} catch (Exception e) {
					RaspberryLogger.getInstance().error(e);
				}
			}
			BackgroundService bs = new BackgroundService();
			bs.start();
			UiApplication.getUiApplication().invokeLater(new Runnable() {
				public void run() {
//					WelcomeScreen ws = new WelcomeScreen();
					PlayerScreen screen=new PlayerScreen();
					UiApplication.getUiApplication().pushScreen(screen);

//					if (!Preferences.registered) {
//						UiApplication.getUiApplication().pushScreen(
//								new RegisterPopupScreen());
//					} else {
//						if (AuthenticationBo.loginServer())
//							UiApplication.getUiApplication().pushScreen(
//									new TabsScreen());
//						else
//							Dialog.alert("登录失败！");
//					}
				}
			});
		}
	}
}
